''''
拆包：将列表、元祖或字典，中的元素编程独立的变量
解包：将独立的变量，变成列表、元祖或字典中的元素
'''


# 列表拆包
numbers = [1, 2, 3]
a, b, c = numbers
print(a, b, c)  # 输出：1 2 3


# 元组拆包
fruits = ('apple', 'banana', 'cherry')
x, y, z = fruits
print(x, y, z)  # 输出：apple banana cherry


# 字典拆包
person = {'name': 'John', 'age': 30, 'city': 'New York'}
name, age, city = person.values()
print(name, age, city)  # 输出：John 30 New York


# 列表解包
a = 1
b = 2
c = 3
numbers = [a, b, c]
print(numbers)  # 输出：[1, 2, 3]


# 元组解包
x = 'apple'
y = 'banana'
z = 'cherry'
fruits = (x, y, z)
print(fruits)  # 输出：('apple', 'banana', 'cherry')


# 字典解包
name = 'John'
age = 30
city = 'New York'
person = {'name': name, 'age': age, 'city': city}
print(person)  # 输出：{'name': 'John', 'age': 30, 'city': 'New York'}


# 字典拆包
person = {'name': 'John', 'age': 30, 'city': 'New York'}
info = {**person}
print(info)  # 输出：{'name': 'John', 'age': 30, 'city': 'New York'}
print(name, info)  # 输出：John {'age': 30, 'city': 'New York'}


# 字典解包
name = 'John'
info = {'age': 30, 'city': 'New York'}
person = {name: info}
print(person)  # 输出：{'John': {'age': 30, 'city': 'New York'}}
